import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  build: {
    outDir: "dist",
    minify: "esbuild",
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖2.05/3.02
      // external: ['vue', 'axios', 'vueRouter']
      // external: ['tinymce/tinymce']
      output: {
        chunkFileNames: (info) => {
          if (info.name.indexOf("_") === 0) {
            return "assets/js[name]-[hash].js";
          } else {
            return "assets/[name]-[hash].js";
          }
        },
      },
    },
  },
  server: {
    base: "/",
    hmr: true,
    // port: 3000,
    host: "0.0.0.0",
    cors: true,
    proxy: {
      "/api": {
        target: "https://m.baoming.sem110u.cn",
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
});
